package com.livesource.client.web.project;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.livesource.client.InitializeLiveSource;
import com.livesource.client.model.project.Project;
import com.livesource.client.web.LiveSourcePage;
import com.livesource.client.web.sourceCode.filesTree.SourceFilesFiltersList;
import com.livesource.client.webservices.project.RequestSaveProject;

/**
 * 
 * @UserInterface
 */
public class ButtonSave extends Button {

	public ButtonSave(final Project project) {

		this.setText("Save");

		this.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				// project.setName(ProjectForm.name.getValue());

				project.setRepositoryType(ProjectForm.repositoryType
						.getValue(ProjectForm.repositoryType.getSelectedIndex()));

				project.setRepositoryURL(ProjectForm.url.getValue());

				RequestSaveProject.sendPostRequest(project);

				InitializeLiveSource.vpLiveSource.clear();

				InitializeLiveSource.vpLiveSource.add(new LiveSourcePage(
						SourceFilesFiltersList.VIEW_CLASS_FILES));

				InitializeLiveSource.loadPanel();
			}
		});

	}
}